package com.company.Demo;

import java.util.Scanner;

public class ZK {
    public static void main(String[] args) {
        String a = "113";
        System.out.println(test(a));
    }
    public static double test(String str){
       if(str==null||"".equals(str.trim())){
           return 0;
       }
       int flag = 1;
       if(str.charAt(0)=='-'){
           flag=0;
           str = str.substring(1,str.length());
       }
       //去掉空格
       str = str.trim();
       double res = 0;
        String[] strings = str.split("\\.");
        if(strings.length>2){
            System.out.println("输入不合法");
            return -1;
        }
        //整数部分
        int sum = 0;
        for(int i=0;i<strings[0].length();i++){
            if(strings[0].charAt(i)-'0'<0||strings[0].charAt(i)-'0'>9){
                System.out.println("输入不合法");
                return -1;
            }
            int val = strings[0].charAt(i)-'0';
            sum += val*makeInteger(strings[0].length()-i-1);
        }
        //小数部分
        int dec = 0;
        for(int i=0;i<strings[1].length();i++){
            if(strings[1].charAt(i)-'0'<0||strings[1].charAt(i)-'0'>9){
                System.out.println("输入不合法");
                return -1;
            }
            int val = strings[1].charAt(i)-'0';
            dec += makeInteger(strings[1].length()-i-1)*val;
        }
        res  = dec*makeDouble(strings[1].length());
        res += sum;
        if(flag==0){
            res *= -1;
        }
       return res;
    }
   public static  int makeInteger(int n){
        int i = 1;
        for(int j =0;j<n;j++){
            i*=10;
        }
        return i;
   }
   public static double makeDouble(int n){
        double i = 1;
        for(int j =0;j<n;j++){
            i/=10;
        }
        return i;
   }
}
